<?php include $this->getViewFile('/common/Head') ?>
<body class="J_scroll_fixed">
<style>
.col-left{float:left}
.col-auto{overflow:hidden;_zoom:1;_float:left;}
.title-1{border-bottom:1px solid #eee; padding-left:5px}
.f14{font-size: 14px}
.lh28{line-height: 28px}
.blue,.blue a{color:#004499}
.gray4,a.gray4{color:#999;}
.lh22{line-height: 22px}
.lh25{line-height: 25px}
.lh30{line-height: 30px}
</style>
<div class="wrap J_check_wrap">
  <?php include $this->getViewFile('/common/Nav') ?>
  <div class="h_a">查找</div>
  <form method="post" action="" id="searchForm">
    <div class="search_type cc mb10">
      <div class="mb10"> 
        状态：<?php echo Form::select(array(
		3 => '所有显示',
		1 => '正在显示',
		4 => '即将显示',
		2 => '已过期',
		0 => '已下架',
		),$status,'name="status"','不限') ?>
        上架时间：
        <input type="text" name="start_time" class="input length_2 J_date" value="<?php echo $start_time?>" placeholder="选择起始时间">
        -
        <input type="text" class="input length_2 J_date" name="end_time" value="<?php echo $end_time?>" placeholder="选择结束时间">
       <!--</div>
       <div class="mb10">-->
        栏目：
        <select class="select_2" name="cat_id">
          <option value=''>不限</option>
          <?php  echo CategoryModel::model()->htmlCategorySelectOption($cat_id); ?>
        </select>
        Level：<?php echo Form::select(CustomBlockModel::model()->getLevelArray(),$level,'name="level"','不限') ?>
        店铺类型：<?php echo Form::select(array(0=>'淘宝',1=>'天猫',2=>'天猫精品'),$item_type,'name="item_type"','不限') ?>
      </div>
      <div class="mb10">
        关键字：<?php echo Form::select(array(1=>'商品ID',2=>'商品名称',3=>'商品旺旺'),$type,'name="type"') ?>
        <input type="text" class="input length_2" name="keyword" style="width:200px;" value="<?php echo $keyword?>" placeholder="请输入搜索内容...">
        <button class="btn">搜索</button>
      </div>
    </div>
  </form>
  <div class="mb10"> 共有 ( <b><?php echo $count; ?></b> ) 个宝贝  
  <?php
  if(RBAC::authenticate('batch_expired')){
  ?>
  <a href="<?php echo AdminBase::U('batch_expired'); ?>" style="color:#F00" class="J_ajax_batch_expired">一键删除已过期商品</a>
  <?php
  }
  ?>
  </div>
  <form name="myform" action="<?php echo AdminBase::U("delete") ?>" method="post" class="J_ajaxForm">
    <div class="table_list">
      <table width="100%" cellspacing="0">
        <thead>
          <tr>
            <td width="100" align="center"><input type="checkbox" class="J_check_all" data-direction="x" data-checklist="J_check_x">全选</td>
            <td align="center">商品报名信息</td>
            <td width="100" align="center">所属栏目</td>
            <td width="80" align="center">排序</td>
            <td width="120" align="center">管理操作</td>
          </tr>
        </thead>
        <tbody>
          <?php
		  foreach($data as $rs){
		  ?>
          <tr id="gbinfo_<?php echo $rs->goods_id;?>">
            <?php include $this->getViewFile('public_load'); ?>
          </tr>
          <?php
		  }
		  ?>
        </tbody>
      </table>
      <div class="p10">
        <div class="pages"><?php echo $Page;?></div>
      </div>
    </div>
  </form>
</div>
<script src="<?php echo $staticUrl; ?>statics/js/common.js"></script>
<script>
//加载信息
function loadGoods(goods_id){
	$.get('<?php echo AdminBase::U("public_load") ?>',{goods_id:goods_id},function(data){
		if(data != ''){
			$("#gbinfo_"+goods_id).html(data);
			changes();
		}
	});
}
//快速编辑
function fastEdit(gid) {
    Wind.use("artDialog", "iframeTools", function () {
		var dialog = art.dialog({
		    title: '快速编辑',
            id: 'fastEdit',
            lock: true,
            fixed: true,
			width:600,
			height:475,
            background: "#CCCCCC",
			padding:'5px 5px',
            opacity: 0
		});
		$.get("<?php echo AdminBase::U("edit") ?>",{ajax:1,goods_id:gid},function(data){
			 if(data == 'no'){
				 alert('该信息不存在！');
				 return false;
			 }
			 dialog.content(data);
		});
        /*art.dialog.open('<?php echo AdminBase::U("edit") ?>?ajax=1&goods_id='+gid, {
            title: '快速编辑',
            id: 'fastEdit',
            lock: true,
            fixed: true,
			width:600,
			height:560,
            background: "#CCCCCC",
            opacity: 0
        });*/
    });
}
//保存
function saveData(data){
	Wind.use("artDialog", "iframeTools", function () {
		$.post('<?php echo AdminBase::U("edit") ?>',data,function(rs){
			if(rs.status){
				art.dialog.tips('修改成功！', 1.5);
			}else{
				art.dialog.tips(rs.info, 3);
			}
			//重新加载
			loadGoods(data.goods_id);
		},'json');
	});
}

//绑定修改事件
function changes(){
	if ($('a.J_ajax_notice').length) {
		Wind.use('artDialog','iframeTools', function () {
			$('.J_ajax_notice').on('click', function (e) {
				e.preventDefault();
				var url = $(this).attr('href');
				var product_id = $(this).data('product_id');
				var dialog = art.dialog({
					title: '信息通知',
					id: 'notice',
					lock: true,
					fixed: true,
					width:600,
					height:70,
					background: "#CCCCCC",
					padding:'5px 5px',
					opacity: 0,
					button:[{
						name:'确定',
						callback:function(){
							var notice = $('form#notice textarea[name="notice"]').val();
							if(notice == ''){
								alert('信息内容不能为空！');
								return false;
							}
							$.getJSON(url,{notice:notice},function(data){
								alert(data.info);
								if(data.status){
									art.dialog.list['notice'].close();
								}
								return true;
							});
							return false;
						},
						focus: true
					}]
				});
				var data = '<div style="overflow:hidden;padding: 5px; ">\
				<form action="<?php echo AdminBase::U("goodsbm/notice") ?>" method="post" id="notice">\
				<div class="table_full">\
				  <table width="100%" class="table_form contentWrap">\
				     <tbody>\
					 <tr>\
					 <th width="80">信息内容</td>\
					 <td><textarea type="text" name="notice" cols="60" rows="3" style="height:50px;width:400px;">亲，您的商品('+product_id+')已经进入初审阶段，请到“报名查询”页面查询商品审核进展（查询后有审核人员旺旺），并联系洽谈。</textarea></td>\
					 </tr>\
					 </tbody>\
				   </table>\
				</div>\
				</form>\
				</div>';
				dialog.content(data);
			});
		});
	}
	//标题修改
	$('input[name="goods_name"]').change(function(){
		var goods_id = $(this).data('gid');
		var goods_name = $(this).val();
		if(goods_name != '' && goods_id > 0){
			var data = {goods_id:goods_id,goods_name:goods_name};
			saveData(data);
			return true;
		}
		return false;
	});
	//活动价格
	$('input[name="promo_price"]').change(function(){
		var goods_id = $(this).data('gid');
		var promo_price = $(this).val();
		if(promo_price != '' && goods_id > 0){
			var data = {goods_id:goods_id,promo_price:promo_price};
			saveData(data);
			return true;
		}
		return false;
	});
	//销量
	$('input[name="sales"]').change(function(){
		var goods_id = $(this).data('gid');
		var sales = $(this).val();
		if(sales != '' && goods_id > 0){
			var data = {goods_id:goods_id,sales:sales};
			saveData(data);
			return true;
		}
		return false;
	});
	//上架时间
	$('input[name="start_time"]').change(function(){
		var goods_id = $(this).data('gid');
		var start_time = $(this).val();
		if(start_time != '' && goods_id > 0){
			var data = {goods_id:goods_id,start_time:start_time};
			saveData(data);
			return true;
		}
		return false;
	});
	//下架时间
	$('input[name="end_time"]').change(function(){
		var goods_id = $(this).data('gid');
		var end_time = $(this).val();
		if(end_time != '' && goods_id > 0){
			var data = {goods_id:goods_id,end_time:end_time};
			saveData(data);
			return true;
		}
		return false;
	});
	//排序
	$('input[name="listorder"]').change(function(){
		var goods_id = $(this).data('gid');
		var listorder = $(this).val();
		if(listorder != '' && goods_id > 0){
			var data = {goods_id:goods_id,listorder:listorder};
			saveData(data);
			return true;
		}
		return false;
	});
	//Level
	$('select[name="level"]').change(function(){
		var goods_id = $(this).data('gid');
		var level = $(this).val();
		if(goods_id > 0){
			var data = {goods_id:goods_id,level:level};
			saveData(data);
			return true;
		}
		return false;
	});
	//店铺类型
	$('select[name="item_type"]').change(function(){
		var goods_id = $(this).data('gid');
		var item_type = $(this).val();
		if(goods_id > 0){
			var data = {goods_id:goods_id,item_type:item_type};
			saveData(data);
			return true;
		}
		return false;
	});
	//栏目
	$('select[name="cat_id"]').change(function(){
		var goods_id = $(this).data('gid');
		var cat_id = $(this).val();
		if(cat_id != '' && goods_id > 0){
			var data = {goods_id:goods_id,cat_id:cat_id};
			saveData(data);
			return true;
		}
		return false;
	});
}

//change事件，值改变
$(function(){
	changes();
	//批量删除过期商品
	if ($('a.J_ajax_batch_expired').length) {
        Wind.use('artDialog', 'iframeTools', function() {
            $('.J_ajax_batch_expired').on('click', function(e) {
                e.preventDefault();
                var $_this = this,
                    $this = $($_this),
                    href = $this.prop('href'),
                    msg = $this.data('msg');
                art.dialog({
                    title: false,
                    icon: 'question',
                    content: '确定要进行此项操作吗？该操作不可恢复！',
                    follow: $_this,
                    close: function() {
                        $_this.focus();; //关闭时让触发弹窗的元素获取焦点
                        return true;
                    },
                    ok: function() {
                        $.getJSON(href).done(function(data) {
                            if (data.state === 'success') {
                                if (data.referer) {
                                    location.href = data.referer;
                                } else {
                                    reloadPage(window);
                                }
                            } else if (data.state === 'fail') {
                                art.dialog.alert(data.info);
                            }
                        });
                    },
                    cancelVal: '关闭',
                    cancel: true
                });
            });

        });
    }
});
</script>
</body>
</html>